﻿<Page
    x:Class="CoachingOrganizer.WinPhone.Pages.Tools.MoneyCalculation.MoneyCalculationPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CoachingOrganizer.WinPhone.Pages.Tools.MoneyCalculation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="using:Microsoft.Xaml.Interactivity"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <Grid x:Name="LayoutRoot">

        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Title Panel -->
        <StackPanel Grid.Row="0" Margin="19,0,0,0">
            <TextBlock x:Uid="ApplicationTitle" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/>
            <TextBlock Text="page title" Margin="0,-6.5,0,26.5" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
        </StackPanel>

        <!--TODO: Content should be placed within the following grid-->
        <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
            <FlipView>
                <FlipViewItem DataContext="{Binding Incomes}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <AutoSuggestBox Text="{Binding NewStableItemName}" ItemsSource="{Binding StableItemsNameSuggestions}"/>
                        <Button Grid.Column="1" Command="{Binding AddNewStableItemCommand}"/>
                        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding StableItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                        <ComboBox Grid.Column="1" SelectedIndex="{Binding PeriodIndex}">
                                            <ComboBoxItem x:Uid="Day"/>
                                            <ComboBoxItem x:Uid="Week"/>
                                            <ComboBoxItem x:Uid="Month"/>
                                            <ComboBoxItem x:Uid="Year"/>
                                        </ComboBox>
                                        <TextBox Grid.Column="2" Text="{Binding Amount, UpdateSourceTrigger=PropertyChanged}"/>
                                        <Button x:Uid="Remove" Grid.Column="3" Command="{Binding RemoveCommand}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </FlipViewItem>
                <FlipViewItem DataContext="{Binding Incomes}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <AutoSuggestBox Text="{Binding NewOccasionalItemName}" ItemsSource="{Binding OccasionalItemsNameSuggestions}"/>
                        <Button Grid.Column="1" Command="{Binding AddNewOccasionalItemCommand}"/>
                        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding OccasionalItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                        <DatePicker Grid.Column="1" Date="{Binding Date}"/>
                                        <TimePicker Grid.Column="2" Time="{Binding Time}"/>
                                        <TextBox Grid.Column="3" Text="{Binding Amount, UpdateSourceTrigger=PropertyChanged}"/>
                                        <Button x:Uid="Remove" Grid.Column="4" Command="{Binding RemoveCommand}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </FlipViewItem>
                <FlipViewItem DataContext="{Binding Spents}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <AutoSuggestBox Text="{Binding NewOccasionalItemName}" ItemsSource="{Binding OccasionalItemsNameSuggestions}"/>
                        <Button Grid.Column="1" Command="{Binding AddNewOccasionalItemCommand}"/>
                        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding OccasionalItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                        <DatePicker Grid.Column="1" Date="{Binding Date}"/>
                                        <TimePicker Grid.Column="2" Time="{Binding Time}"/>
                                        <TextBox Grid.Column="3" Text="{Binding Amount, UpdateSourceTrigger=PropertyChanged}"/>
                                        <Button x:Uid="Remove" Grid.Column="4" Command="{Binding RemoveCommand}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </FlipViewItem>
                <FlipViewItem DataContext="{Binding Spents}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <AutoSuggestBox Text="{Binding NewStableItemName}" ItemsSource="{Binding StableItemsNameSuggestions}"/>
                        <Button Grid.Column="1" Command="{Binding AddNewStableItemCommand}"/>
                        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding StableItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <TextBox Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                        <ComboBox Grid.Column="1" SelectedIndex="{Binding PeriodIndex}">
                                            <ComboBoxItem x:Uid="Day"/>
                                            <ComboBoxItem x:Uid="Week"/>
                                            <ComboBoxItem x:Uid="Month"/>
                                            <ComboBoxItem x:Uid="Year"/>
                                        </ComboBox>
                                        <TextBox Grid.Column="2" Text="{Binding Amount, UpdateSourceTrigger=PropertyChanged}"/>
                                        <Button x:Uid="Remove" Grid.Column="3" Command="{Binding RemoveCommand}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </FlipViewItem>
                <FlipViewItem DataContext="{Binding Report}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <ComboBox SelectedIndex="{Binding PeriodSizeIndex}">
                            <ComboBoxItem x:Uid="Day"/>
                            <ComboBoxItem x:Uid="Week"/>
                            <ComboBoxItem x:Uid="Month"/>
                            <ComboBoxItem x:Uid="Year"/>
                        </ComboBox>
                        <ComboBox Grid.Column="1" ItemsSource="{Binding PeriodReports}" DisplayMemberPath="StrPeriod" SelectedItem="{Binding CurrentPeriodReport}"/>
                        <Grid Grid.Row="1" Grid.ColumnSpan="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <TextBlock Text="{Binding TotalIncomes}"/>
                            <TextBlock Text="{Binding TotalSpents}" Grid.Column="1"/>
                            <TextBlock Text="{Binding TotalSummary}" Grid.Column="2"/>
                        </Grid>
                        <ListView Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding ReportItems}">
                            <ListView.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Name}"/>
                                        <TextBlock Foreground="{Binding MarkColor}" Text="{Binding Amount}"/>
                                    </Grid>
                                </DataTemplate>
                            </ListView.ItemTemplate>
                        </ListView>
                    </Grid>
                </FlipViewItem>
                <FlipViewItem>

                </FlipViewItem>
            </FlipView>
        </Grid>
    </Grid>
</Page>
